package cn.mrcode.mrweb;

import cn.mrcode.smartFramework.helper.DataBaseHelper;
import cn.mrcode.smartPluginSecurity.SmartSecurity;

import java.util.Set;

/**
 * 完成相应的数据库的操作。
 * @author zhuqiang
 * @version V1.0
 * @date 2015/11/14 23:05
 */
public class AppSecurity implements SmartSecurity {
    @Override
    public String getPassword(String username) {
        String sql ="SELECT `password` FROM `user` WHERE username = ?";
        return DataBaseHelper.queryColumn(sql, username);
    }
    @Override
    public Set<String> getRoleNameSet(String username) {
        String sql = "SELECT r.role_name FROM `user` u,user_role ur,role r WHERE u.id = ur.user_id AND ur.role_id = r.id AND u.username=?";
        return DataBaseHelper.queryColumnSet(sql, username);
    }
    @Override
    public Set<String> getPermissionNameSet(String roleName) {
        String sql = "SELECT p.permission_name FROM role r,role_permission rp,permission p WHERE r.id = rp.role_id AND rp.permission_id = p.permission_name AND r.role_name = ?";
        return DataBaseHelper.queryColumnSet(sql,roleName);
    }
}
